**************************************************************************************************
/*
Creators: Maximilian J. Pany & Raha Imanirad
Course: Gov 2001 / Stat E-200
Date: 5/4/2015
Article:
	Blowing smoke

Replicated Article: 
	Adoption and compliance in second-hand smoking bans: a global econometric analysis
	Richard Perkins, Eric Neumayer
	Int J Public Health (2014) 59:859�866
*/
**************************************************************************************************

**************************************************************************************************
*** This do file creates the replication results for 
*** Adoption and Compliance in Second-Hand Smoking Bans: A Global Econometric Analysis	 					 	*/
*** Richard Perkins (LSE)														*/
*** Eric Neumayer (LSE)																			*/
*** 																							*/
*** Published in: International Journal of Public Health, 59 (5), 2014, pp. 859-866 													*/
**************************************************************************************************
**************************************************************************************************
/* Note: 
You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 													*/
**************************************************************************************************

version 12.0
drop _all
clear matrix
clear mata
set more off

capture net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o)			/* checks whether outreg2 is installed 		*/

**************************************************************************************************
/* Note:
Need to install the -listcoef- command for all parts of this DO file to work properly.
To do so, type -findit spostado- and install the spost9_ado package.
This is NOT necessary to replicate Pany & Imanirad (2015).
*/
**************************************************************************************************

***********************************************************************************
local DIR = "~/Google Drive/gov2001/paper/"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************

use smoke_2010.dta, replace


***********************************************************************************
* Switching to a directory that was created in smoke_2008.do to store the tables created herein *
cd tmp
* Creating directory for this year *
cap !mkdir 2010
cd 2010
***********************************************************************************

** Fixing Cote d'Ivoire name and order to fit with other years **
replace country = "C�te d'Ivoire" if country == "C�te d'Ivoire"

** Fixing Libya's name to fit with other years **
replace country = "Libya" if country == "Libyan Arab Jamahiriya"
sort country

/*
P1	National smoking ban in HEALTH-CARE FACILITIES
P2	National smoking ban in EDUCATIONAL FACILITIES EXCEPT UNIVERSITIES
P3	National smoking ban in UNIVERSITIES
P4	National smoking ban in GOVERNMENT FACILITIES
P5	National smoking ban in INDOOR OFFICES
P6	National smoking ban in RESTAURANTS
P7	National smoking ban in PUBS AND BARS
P8	National smoking ban in PUBLIC TRANSPORT
P9	National smoking ban in ALL OTHER INDOOR PUBLIC PLACES
*/


capture drop smoke_ban_health smoke_ban_edu smoke_ban_government smoke_ban_offices smoke_ban_pubtransport

gen smoke_ban_health=0
replace smoke_ban_health=1 if p1=="Yes"

gen smoke_ban_edu=0
replace smoke_ban_edu=1 if p2=="Yes" | p3=="Yes"

gen smoke_ban_government=0
replace smoke_ban_government=1 if p4=="Yes"

gen smoke_ban_offices=0
replace smoke_ban_offices=1 if p5=="Yes"

gen smoke_ban_pubtransport=0
replace smoke_ban_pubtransport=1 if p8=="Yes"

** Fill missing demographic structure data with data from CIA World Fact Book
replace pop_15_64=70.9 if wb_country_name=="Seychelles"
replace pop_65up=7.3 if wb_country_name=="Seychelles"
replace pop_15_64=70.9 if wb_country_name=="Palau"
replace pop_65up=6.8 if wb_country_name=="Palau"
replace pop_15_64=66.7 if wb_country_name=="Antigua and Barbuda"
replace pop_65up=7.1 if wb_country_name=="Antigua and Barbuda"
replace pop_15_64=68.7 if wb_country_name=="Dominica"
replace pop_65up=10.4 if wb_country_name=="Dominica"
replace pop_15_64=63.1 if wb_country_name=="Kiribati"
replace pop_65up=3.9 if wb_country_name=="Kiribati"
replace pop_15_64=68.4 if wb_country_name=="St. Kitts and Nevis"
replace pop_65up=7.8 if wb_country_name=="St. Kitts and Nevis"

** Change the scale of tobacco production variable
replace tobacco_production_filled0=tobacco_production_filled0/1000

** Save processed data for later use in R **
saveold smoke_2010_mod.dta, replace


***********************************************************************************
*** Multiple Imputation ***
capture mi extract 0, clear
mi set wide
mi register imputed cigarette_consumption  health_exp_to_gov_exp ln_gdp_pc
capture mi xtset, clear
capture mi stset, clear
mi impute mvn ln_gdp_pc  cigarette_consumption health_exp_to_gov_exp = smoke_ban_rest_or_bars_who smoke_ban_health smoke_ban_edu smoke_ban_government smoke_ban_offices smoke_ban_pubtransport rule_law_est   tobacco_production_filled0 developed- reg_lac  pop_t- life_exp,  add(100) replace force rseed(2232)

** Save MI data, with MI indicators, for later use in R **
gen mi_ln_gdp_pc = 0
replace mi_ln_gdp_pc = 1 if ln_gdp_pc == . & _1_ln_gdp_pc != .

gen mi_cigarette_consumption = 0
replace mi_cigarette_consumption = 1 if cigarette_consumption == . & _1_cigarette_consumption != .

gen mi_health_exp_to_gov_exp = 0
replace mi_health_exp_to_gov_exp = 1 if health_exp_to_gov_exp == . & _1_health_exp_to_gov_exp != .

saveold smoke_2010_mi.dta, replace
***********************************************************************************


***********************************************************************************
*** TABLE 1 ***
** Smoking ban incidence (existing sample)
* Ban in restaurants OR bars (NOTE: practically no difference to ban in restaurant only or bar only or ban in both)
probit  smoke_ban_rest_or_bars_who  ln_gdp_pc cigarette_consumption tobacco_production_filled0 health_exp_to_gov_exp, robust
* Evaluating model fit *
lroc, nograph  // 66.4%

margins, at( (p25) ln_gdp_pc) 
margins, at( (p75) ln_gdp_pc) 
margins, dydx(*) post
outreg2 using table1.txt, replace excel ci level(95) 2aster  dec(2) sideway

ivprobit  smoke_ban_rest_or_bars_who   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp (cigarette_consumption= pop_15_64 pop_65up ) , robust
* Evaluating model fit *
lroc, nograph  // 66.0%

margins, at( (p25) ln_gdp_pc)  predict(pr)
margins, at( (p75) ln_gdp_pc)  predict(pr)
margins, dydx(*) post  predict(pr)
outreg2 using table1.txt, append excel ci level(95) 2aster  dec(2) sideway


** Program for AUC analysis after MI **
cap program drop eroctab
program eroctab, eclass
        version 12.0

        /* Step 1: perform ROC analysis */
        args refvar classvar
        roctab `refvar' `classvar'

        /* Step 2: save estimate and its variance in temporary matrices*/
        tempname b V
        mat `b' = r(area)
        mat `V' = r(se)^2
	local N = r(N)

        /* Step 3: make column names and row names consistent*/
        mat colnames `b' = AUC
        mat colnames `V' = AUC
        mat rownames `V' = AUC

        /*Step 4: post results to e()*/
        ereturn post `b' `V', obs(`N')
        ereturn local cmd "eroctab"
        ereturn local title "ROC area"
end


** Smoking ban incidence (multiply imputed sample)
capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
	probit  smoke_ban_rest_or_bars_who  ln_gdp_pc cigarette_consumption    tobacco_production_filled0 health_exp_to_gov_exp, robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
* Evaluating model fit *
mi estimate, cmdok: eroctab smoke_ban_rest_or_bars_who  ln_gdp_pc cigarette_consumption    tobacco_production_filled0 health_exp_to_gov_exp  // 63.2%

capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
	probit  smoke_ban_rest_or_bars_who  ln_gdp_pc cigarette_consumption    tobacco_production_filled0 health_exp_to_gov_exp, robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
outreg2 using table1.txt, append excel ci level(95) 2aster  dec(2) sideway

capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
	ivprobit  smoke_ban_rest_or_bars_who   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp (cigarette_consumption= pop_15_64 pop_65up ) , robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
outreg2 using table1.txt, append excel ci level(95) 2aster  dec(2) sideway
***********************************************************************************


***********************************************************************************
*** TABLE 2 ***
** Ban health facilities
capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
  ivprobit  smoke_ban_health ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp (cigarette_consumption= pop_15_64 pop_65up ) , robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
outreg2 using table2.txt, replace excel ci level(95) 2aster  dec(2) sideway

** Ban education facilities
capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
  ivprobit  smoke_ban_edu   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp (cigarette_consumption= pop_15_64 pop_65up ) , robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
outreg2 using table2.txt, append excel ci level(95) 2aster  dec(2) sideway

** Ban government facilities
capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
  ivprobit  smoke_ban_government   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp (cigarette_consumption= pop_15_64 pop_65up ) , robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
outreg2 using table2.txt, append excel ci level(95) 2aster  dec(2) sideway

** Ban offices
capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
  ivprobit  smoke_ban_offices   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp (cigarette_consumption= pop_15_64 pop_65up ) , robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
outreg2 using table2.txt, append excel ci level(95) 2aster  dec(2) sideway

** Ban public transport
capture program drop mimargins 
program mimargins, eclass properties(mi)
  version 12
  ivprobit  smoke_ban_pubtransport   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp (cigarette_consumption= pop_15_64 pop_65up ) , robust
  margins, dydx(*)  predict(pr) post
end
mi estimate, post cmdok: mimargins 1
outreg2 using table2.txt, append excel ci level(95) 2aster  dec(2) sideway
***********************************************************************************


***********************************************************************************
*** TABLE 3 ***
** Smoking ban enforcement (full sample)
ologit  smoke_ban_enforcement cigarette_consumption  ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban, robust
outreg2 using table3.txt, replace excel ci level(95) 2aster  dec(2) sideway
/*
listcoef
listcoef, reverse
listcoef, percent 
listcoef, percent reverse
*/

ivreg2 smoke_ban_enforcement   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban (cigarette_consumption= pop_15_64 pop_65up) , robust first
outreg2 using table3.txt, append excel ci level(95) 2aster  dec(2) sideway

mi estimate, post dots: ologit  smoke_ban_enforcement cigarette_consumption  ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban, robust
outreg2 using table3.txt, append excel ci level(95) 2aster  dec(2) sideway

mi estimate, post dots cmdok: ivreg2 smoke_ban_enforcement   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban (cigarette_consumption= pop_15_64 pop_65up) , robust
outreg2 using table3.txt, append excel ci level(95) 2aster  dec(2) sideway
***********************************************************************************


***********************************************************************************
*** TABLE 4 ***
** Smoking ban enforcement (non-OECD sample)
ologit  smoke_ban_enforcement cigarette_consumption  ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban if inc_high_oecd==0, robust
outreg2 using table4.txt, replace excel ci level(95) 2aster  dec(2) sideway
/*
listcoef
listcoef, reverse
listcoef, percent 
listcoef, percent reverse
*/

ivreg2 smoke_ban_enforcement   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban (cigarette_consumption= pop_15_64 pop_65up)  if inc_high_oecd==0, robust first
outreg2 using table4.txt, append excel ci level(95) 2aster  dec(2) sideway

mi estimate, post dots: ologit  smoke_ban_enforcement cigarette_consumption  ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban if inc_high_oecd==0, robust
outreg2 using table4.txt, append excel ci level(95) 2aster  dec(2) sideway

mi estimate, post dots cmdok: ivreg2 smoke_ban_enforcement   ln_gdp_pc  tobacco_production_filled0 health_exp_to_gov_exp  smoke_ban_number yearsof_partial_rest_ban yearsof_partial_gov_ban yearsof_partial_school_ban yearsof_partial_hospital_ban yearsof_partial_transp_ban (cigarette_consumption= pop_15_64 pop_65up)  if inc_high_oecd==0, robust
outreg2 using table4.txt, append excel ci level(95) 2aster  dec(2) sideway
***********************************************************************************
